//
//  QCRemeberController.swift
//  爱汽车
//
//  Created by tucici on 2024/10/28.
//

import UIKit

class QCRemeberController: QCViewController {
    var array = ["高度记忆","压力记忆"]
    var values : [Bool] = [false,false]
    var block : ((_ ispressure : Bool)->Void)?
    override func viewDidLoad() {
        super.viewDidLoad()
        initUI()
    }
    override func initUI() {
        title = LS("记忆模式")
        
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(QCSettingCell.nib(), forCellReuseIdentifier: QCSettingCell.ID())
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    override var bytes: [UInt8]{
        didSet{
            let ack = bytes[7]
            if ack != UInt8(AIQC.userInfo.ack){return}
            let data = [UInt8](bytes[AI_index..<bytes.count])
            if recived == false {
//                recived = true
                return
            }
            values[0] = data[0] == 0
            values[1] = data[0] == 1
            tableView.reloadData()
        }
    }
    
    
}
//MARK: - UITableViewDataSource
extension QCRemeberController:UITableViewDataSource
{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: QCSettingCell.ID()) as! QCSettingCell
        cell.title.text = LS(array[indexPath.row])
        cell.type = .switchBtn(values[indexPath.row])
        cell.block = {[weak self] ison in
            self?.recived = false
            self?.values[0] = indexPath.row == 0 ? ison : !ison
            self?.values[1] = indexPath.row == 1 ? ison : !ison
            self?.tableView.reloadData()
            BLEData.appSetDataToPer(AIQC.setHightMode.cmd, ison && indexPath.row == 0 ? "00" : "01").write
            self?.block?(self?.values[1] ?? false)
        }
        return cell
    }
}
//MARK: - UITableViewDelegate
extension QCRemeberController:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return nil
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }
}
